-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
blockchain: Add invalidate/reconsider infrastructure. #2536
blockchain: Add invalidate/reconsider infrastructure. #2536
Conversation
d5c5706
to
7c290c2
Compare
Here is an example of the PR in action on simnet: Invalidate and reconsider same block:$ for i in $(seq 28 1 32); do echo "$(./ctl getblockhash $i) (height $i)"; done
19630e8a7bd723f0d37e7f76b824f43e878ae005063007248220350365bf42d9 (height 28)
0e48bb52098b5bc014f94e42543504f4f5f799aa96601a8ba5e8717632a1ba06 (height 29)
04e9a016058439f4f19c16f9b316dd52259258baf9e0067a311b0ed33c739569 (height 30)
0692d68e9abb2c9049a10e98fa11789df21b90bbd4fe3191d833826117b2040e (height 31)
00c1e024cdadb091e3f24b40c4a73f51704a60b8fbc4a735725c3c1577a20f7a (height 32)
$ ./ctl invalidateblock 04e9a016058439f4f19c16f9b316dd52259258baf9e0067a311b0ed33c739569 # height 30
$ ./ctl getbestblockhash | ./ctl getblockheader - | jq '{height,hash}'
{
"height": 29,
"hash": "0e48bb52098b5bc014f94e42543504f4f5f799aa96601a8ba5e8717632a1ba06"
}
$ ./ctl reconsiderblock 04e9a016058439f4f19c16f9b316dd52259258baf9e0067a311b0ed33c739569 # height 30
$ ./ctl getbestblockhash | ./ctl getblockheader - | jq '{height,hash}'
{
"height": 32,
"hash": "00c1e024cdadb091e3f24b40c4a73f51704a60b8fbc4a735725c3c1577a20f7a"
} Nested invalidate and reconsider:$ ./ctl invalidateblock 0692d68e9abb2c9049a10e98fa11789df21b90bbd4fe3191d833826117b2040e # height 31
$ ./ctl invalidateblock 0e48bb52098b5bc014f94e42543504f4f5f799aa96601a8ba5e8717632a1ba06 # height 29
$ ./ctl getbestblockhash | ./ctl getblockheader - | jq '{height,hash}'
{
"height": 28,
"hash": "19630e8a7bd723f0d37e7f76b824f43e878ae005063007248220350365bf42d9"
}
$ ./ctl reconsiderblock 0e48bb52098b5bc014f94e42543504f4f5f799aa96601a8ba5e8717632a1ba06 # height 29
$ ./ctl getbestblockhash | ./ctl getblockheader - | jq '{height,hash}'
{
"height": 30,
"hash": "04e9a016058439f4f19c16f9b316dd52259258baf9e0067a311b0ed33c739569"
}
$ ./ctl reconsiderblock 0692d68e9abb2c9049a10e98fa11789df21b90bbd4fe3191d833826117b2040e # height 31
$ ./ctl getbestblockhash | ./ctl getblockheader - | jq '{height,hash}'
{
"height": 32,
"hash": "00c1e024cdadb091e3f24b40c4a73f51704a60b8fbc4a735725c3c1577a20f7a"
} Reconsider descendant of one or more invalidated ancestors:$ ./ctl invalidateblock 0692d68e9abb2c9049a10e98fa11789df21b90bbd4fe3191d833826117b2040e # height 31
$ ./ctl getbestblockhash | ./ctl getblockheader - | jq '{height,hash}'
{
"height": 30,
"hash": "04e9a016058439f4f19c16f9b316dd52259258baf9e0067a311b0ed33c739569"
}
$ ./ctl invalidateblock 0e48bb52098b5bc014f94e42543504f4f5f799aa96601a8ba5e8717632a1ba06 # height 29
{
"height": 28,
"hash": "19630e8a7bd723f0d37e7f76b824f43e878ae005063007248220350365bf42d9"
}
$ ./ctl reconsiderblock 00c1e024cdadb091e3f24b40c4a73f51704a60b8fbc4a735725c3c1577a20f7a # height 32
$ ./ctl getbestblockhash | ./ctl getblockheader - | jq '{height,hash}'
{
"height": 32,
"hash": "00c1e024cdadb091e3f24b40c4a73f51704a60b8fbc4a735725c3c1577a20f7a"
} |
7c290c2
to
584c336
Compare
584c336
to
5103db3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome. I had a few comments inline, and outside of that, everything looks good. I used this to test deep reorgs (up to thousands of blocks deep) against real mainnet data, which wasn't really possible before. I also tested that scenario against #2540 and was able to reproduce an issue, so this has already proven to be very useful!
5103db3
to
2c3189f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on simnet, working as expected. These RPCs are really nice! 👍
2c3189f
to
5c439c0
Compare
I added a couple of logging statements so the commands are not silent and rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Retested with the latest, and everything worked as expected, including the newly added log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When reconsidering, I get a warning for every block: [WRN] FEES: Trying to process mined transactions at block 594631 when previous best block was at height 594641
If I manually invalidate a block, is it possible to undo that without remembering the block hash? If not an rpc call that shows what I have manually disabled would be handy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ran this on mainnet without issue. When started back up, it syncs back to the best height on the network when dcrd is stopped while invalidating/reconsidering arbitrary blocks.
Just have a couple of minor comments.
5c439c0
to
478412b
Compare
@JoeGruffins Yes, that is normal. The fees code doesn't update on reorgs. It probably shouldn't be a warning, but that is not related to this PR, so I'll leave it for another. |
Yes. You can just use
Given the above, I don't think this is really necessary. However, an RPC to show information regarding invalid blocks is not a bad idea! That said, it would have to come with some caveats. Namely, you can't distinguish between a block that was manually marked invalid and one that actually failed consensus validation and this is by design. So, such an RPC would really need to show all blocks that have failed validation which would include both types. It's not something I would want to do as a part of this PR, so it would be something for another day. |
478412b
to
d3c2ae4
Compare
This adds infrastructure to support invalidating arbitrary blocks as if they had violated a consensus rule as well as reconsidering arbitrary blocks for validation under the current consensus rules. It also includes comprehensive tests to ensure proper functionality. Example use cases this enables: - Revalidating blocks under new consensus rules - Consider the case of old software rejecting blocks due to new consensus rules activating on the network and then upgrading to a new version that supports the new rules - Possibility of manually generating snapshots of historical state such as live tickets and available utxos - Manually recovering from unexpected circumstances - Easier chain reorganization testing
This adds the command types for the upcoming invalidateblock and reconsiderblock RPC commands.
This implements the invalidateblock and reconsiderblock RPC commands including the required help strings.
This adds documentation for the new invalidateblock and reconsiderblock RPC commands to the JSON-RPC API docs.
d3c2ae4
to
0e72a3e
Compare
This requires #2518.
This adds infrastructure to support invalidating arbitrary blocks as if they had violated a consensus rule as well as reconsidering arbitrary blocks for validation under the current consensus rules and includes comprehensive tests to ensure proper functionality.
It also adds two new rpc commands
invalidateblock
andreconsiderblock
to expose the new functionality and updates the JSON-RPC API documentation accordingly.Example use cases this enables:
Testing notes:
In order to make the new commands available to
dcrctl
, a replace directive to use the updated and unreleasedtypes
module is needed. The following command from thedcrctl
directory will accomplish that: